package com.tbi.graphcolouring.algorithmconfiguration.creator;

import java.util.ArrayList;
import java.util.List;

import com.tbi.algorithm.configuration.IPopulationCreator;
import com.tbi.graphcolouring.AlgorithmSettings;
import com.tbi.graphcolouring.BaseGraph;
import com.tbi.graphcolouring.PopulationEntity;
import com.tbi.graphcolouring.utils.Random;

public class RandomPopulationCreator implements IPopulationCreator {
	
	public RandomPopulationCreator(int populationSize) {
		AlgorithmSettings.POPULATION_SIZE = populationSize;
	}

	@Override
	public List<Object> createPopulation(Object obj) {
		List<Object> population = new ArrayList<>();
		int graphSize = ((BaseGraph) obj).getNodes().size();
		int populationSize = AlgorithmSettings.POPULATION_SIZE;
		
		for(int i=0; i<populationSize; i++){
			createEntity(population, graphSize);
		}
		
		return population;
	}

	private void createEntity(List<Object> population, int graphSize) {
		PopulationEntity entity = new PopulationEntity(graphSize);
		
		for (int i = 0; i < entity.colors.length; i++) {
			entity.colors[i] = (int)Random.uniform(0, graphSize);
		}
		
		population.add(entity);
	}
	
}
